<!doctype html>
<html lang="zh-CN">
    <head>
        <meta charset="UTF-8" />
        <title>获取Display</title>
        <script>
            async function rtc() {
                var firstRptPeerConn = new RTCPeerConnection();
                var secondRptPeerConn = new RTCPeerConnection();

                var contraints = {
                    audio: true,
                    video: true,
                };

                navigator.mediaDevices
                    .getUserMedia(contraints)
                    .then(function (stream) {
                        stream.getTracks().forEach((track) => {
                            firstRptPeerConn.addTrack(track);
                            secondRptPeerConn.addTrack(track);
                        });
                    });

                var sdpOffer = await firstRptPeerConn.createOffer();
                await firstRptPeerConn.setLocalDescription(sdpOffer);
                await secondRptPeerConn.setRemoteDescription(sdpOffer);

                var sdpAnswer = await secondRptPeerConn.createAnswer();
                await secondRptPeerConn.setLocalDescription(sdpAnswer);
                await firstRptPeerConn.setRemoteDescription(sdpAnswer);

                console.log(secondRptPeerConn.signalingState);
                console.log(firstRptPeerConn.signalingState);
                console.log(firstRptPeerConn.localDescription);
                console.log(firstRptPeerConn.remoteDescription);
                console.log(secondRptPeerConn.localDescription);
                console.log(secondRptPeerConn.remoteDescription);
            }

            rtc();
        </script>
    </head>
    <body>
        <video autoplay controls id="first"></video>
        <button onclick="">Start</button>
    </body>
</html>
